package com.neuedu.filter;

import com.neuedu.dao.impl.TokenDao;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "TokenFilter", urlPatterns = "/his/*")
public class TokenFilter implements Filter {
    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        String name = req.getParameter("username");
        String token = req.getParameter("token");
        if (new TokenDao().getToken(name, token)) {
            chain.doFilter(req, resp);
        } else {
            resp.getWriter().append("false");
        }

    }

    @Override
    public void init(FilterConfig config) throws ServletException {

    }

}
